package cn.tedu.analyse.service.impl;

import cn.tedu.analyse.dao.mapper.RepliesMapper;
import cn.tedu.analyse.pojo.entity.Replies;
import cn.tedu.analyse.pojo.param.RepliesParam;
import cn.tedu.analyse.pojo.vo.RepliesVO;
import cn.tedu.analyse.service.RepliesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class RepliesServiceImpl implements RepliesService {
    @Autowired
    private RepliesMapper repliesMapper;


    @Override
    public void createReply(RepliesParam repliesParam) {
        log.debug("创建回复，参数：{}", repliesParam);
        Replies replies = new Replies();

        replies.setContent(repliesParam.getContent());
        replies.setCreatedAt(new Date());
        replies.setUserId(repliesParam.getUserId());
        replies.setLikeCount(repliesParam.getLikesCount());
        replies.setParentId(repliesParam.getParentId());
        replies.setAnalyseCommentsId(repliesParam.getParentId());

        Long repliesId = repliesParam.getId();
        repliesMapper.selectReplies(repliesId);
        replies.setId(repliesId);

        repliesMapper.createReply(replies);
    }

    @Override
    public void deleteReply(Long repliesId) {
        log.debug("删除回复，参数：{}", repliesId);
        repliesMapper.deleteReply(repliesId);
    }

    @Override
    public List<RepliesVO> listReplies(Long analyseCommentsId) {
        log.debug("查询回复，参数：{}", analyseCommentsId);
        return repliesMapper.listReplies(analyseCommentsId);

    }

    @Override
    public RepliesVO getReplies(Long repliesId) {
        log.debug("查询回复id，参数：{}", repliesId);
        return repliesMapper.selectReplies(repliesId);
    }

    @Override
    public List<RepliesVO> listRepliesByParentId(Long parentId) {
        log.debug("查询回复多级回复，参数：{}", parentId);
        return repliesMapper.listRepliesByParentId(parentId);
    }
}
